package com.century.sjt.activity;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.ImageButton;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.android.volley.RequestQueue;
import com.android.volley.toolbox.Volley;
import com.century.sjt.R;
import com.century.sjt.util.Constant;
import com.century.sjt.widget.TitleBar.SjtTitleBar;

import cn.sharesdk.framework.ShareSDK;
import cn.sharesdk.onekeyshare.OnekeyShare;


public class NewsDetailActivity extends BaseActivity {

    private TextView mTVtitle;
    private WebView mWVcontent;
    //Top属性
    private ImageButton btnSys;                                     //返回按钮
    private TextView mTitle;                                        //程序标题
    private LinearLayout leftLinLayout;                             //左边的线性布局
    private SjtTitleBar titleBar;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_newdetail);

        initView();
        initEvent();
        initData();
    }

    @Override
    protected void initView() {
        mWVcontent = (WebView) findViewById(R.id.news_detail_webview );

        titleBar = (SjtTitleBar) findViewById(R.id.title_bar);
        titleBar.setTitle(getResources().getString(R.string.tab_news_detail));
        //--------------> Top 获取   <-----------------
        titleBar.setLeftLayoutClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                finish();
            }
        });
        titleBar.setRightIconResourc(getResources().getString(R.string.icon_share));

    }

    @Override
    protected void initEvent() {
        //--------------> 新闻详情页面获取数据   <-----------------
        Intent intent = this.getIntent();        //获取已有的intent对象

        final String newsId = intent.getStringExtra("sysid"); //新闻ID
        final String url = intent.getStringExtra("url"); //ShareUrl
        final String image = intent.getStringExtra("image");//分享图片
        final String title = intent.getStringExtra("title");//标题
        final String summary = intent.getStringExtra("summary");//内容

        WebSettings settings = mWVcontent.getSettings();
        settings.setJavaScriptEnabled(true);
//        settings.setBlockNetworkImage(false);
        settings.setLayoutAlgorithm(WebSettings.LayoutAlgorithm.SINGLE_COLUMN);
        titleBar.setRightLayoutClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                showShare(image,title,summary,url);
            }
        });
        mWVcontent.setWebViewClient(new WebViewClient(){
            @Override
            public boolean shouldOverrideUrlLoading(WebView view, String url) {
                //TODO Auto-generated method stub
                //返回值是true的时候控制去WebView打开，为false调用系统浏览器或第三方浏览器
                view.loadUrl(url);
                return true;
            }
        });
        mWVcontent.loadUrl(Constant.GetNewDetail+"?newsId="+newsId);
    }

    @Override
    protected void initData() {

    }

    public void showShare( String LogoURL,String inviteTitle, String inviteContent,String inviteUrl) {
//图片不能为空，地址要有图片

        ShareSDK.initSDK(NewsDetailActivity.this);
        OnekeyShare oks = new OnekeyShare();
        // title标题，印象笔记、邮箱、信息、微信、人人网和QQ空间使用
        oks.setTitleUrl(inviteUrl);
        oks.setTitle(inviteTitle);
        String ImgUrl = Constant.BaseWebHost + LogoURL;
        oks.setImageUrl(ImgUrl);
        oks.setText(inviteContent);
        oks.setUrl(inviteUrl);

        oks.show(NewsDetailActivity.this);




    }


}
